import java.io.InputStream;
import java.util.Vector;

public class middleCode{
	public static singleCode[] Codes;
	public static int num;
	public middleCode(InputStream is)
	{
		symbol_table table=new symbol_table(is);
		num=table.getFindex();
		Codes=new singleCode[num];
		for(int i=0;i<num;i++)
		{
			Codes[i]=new singleCode(table.getFuntionNames()[i]);
		}
	}
	public static boolean add(String name,String s1,String s2,String s3,String s4)
	{
		boolean success=false;
		for(int i=0;i<num;i++)
		{
			if(Codes[i].name.equals(name))
			{
				Codes[i].add(s1, s2, s3, s4);
				success=true;
				
				//debug
				//System.out.print("Insert into middle code(" + name + "): " + s1 + " " + s2 + " " + s3 + " " + s4 + "\n");
			}
			else
			{
				//debug
				//System.out.print("Failed:Insert into middle code(" + name + "): " + s1 + " " + s2 + " " + s3 + " " + s4+ "\n");
			}
		}
		//debug
		System.out.print(success + ": Try to insert into middle code(" + name + "): " + s1 + " " + s2 + " " + s3 + " " + s4 + "\n");
		return success;
	}
	public String get(String name)
	{
		String str="";
		for(int i=0;i<num;i++)
			if(Codes[i].name.equals(name))
			{
				str+=Codes[i].get();
			}
		if(str.length()==0)
			str+=name+" has no code!\n";
		return str;
	}
	public String get(String name,int num1)
	{
		String str="";
		for(int i=0;i<num;i++)
			if(Codes[i].name.equals(name))
			{
				str+=Codes[i].get(num1);
			}
		if(str.length()==0)
			str+=name+" has no code!\n";
		return str;
	}
	public boolean delete(String name,int num1)
	{
		boolean success=false;
		for(int i=0;i<num;i++)
		{
			if(Codes[i].name.equals(name))
			{
				Codes[i].delete(num1);
				success=true;
			}
		}
		return success;
	}
	public boolean clear(String name)
	{
		boolean success=false;
		for(int i=0;i<num;i++)
		{
			if(Codes[i].name.equals(name))
			{
				Codes[i].clear();
				success=true;
			}
		}
		return success;
	}
	public boolean clear()
	{
		for(int i=0;i<num;i++)
		{
			Codes[i].clear();
		}
		return true;
	}
}
